package Model;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

import javax.swing.JOptionPane;

/**
 * Class modeling a standard contact
 * @author Vincent Francolin
 * @version 1.0 : creation
 */
public class Contact {
	private String name;
	private String firstName;
	private String companyAddress;
	private String mobilePhone;
	private String homePhone;
	private String mobilePhonePro;
	private String officePhone;
	private String homePage;
	private String mailPro;
	private String mailPerso;
	private String picPath;
	private String other;
	
	/**
	 * default constructor
	 * @param name
	 * @param firstName
	 * @param companyAddress
	 * @param mobilePhone
	 * @param homePhone
	 * @param mobilePhonePro
	 * @param officePhone
	 * @param homePage
	 * @param mailPro
	 * @param mailPerso
	 * @param other
	 */
	public Contact(String name, String firstName, String companyAddress,
			String mobilePhone, String homePhone, String mobilePhonePro,
			String officePhone, String homePage, String mailPro,
			String mailPerso, String picPath, String other) {
		super();
		this.name = name;
		this.firstName = firstName;
		this.companyAddress = companyAddress;
		this.mobilePhone = mobilePhone;
		this.homePhone = homePhone;
		this.mobilePhonePro = mobilePhonePro;
		this.officePhone = officePhone;
		this.homePage = homePage;
		this.mailPro = mailPro;
		this.mailPerso = mailPerso;
		this.picPath = picPath;
		this.other = other;
	}
	
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	
	public String getCompanyAddress() {
		return companyAddress;
	}
	public void setCompanyAddress(String companyAddress) {
		this.companyAddress = companyAddress;
	}
	
	public String getMobilePhone() {
		return mobilePhone;
	}
	public void setMobilePhone(String mobilePhone) {
		this.mobilePhone = mobilePhone;
	}
	
	public String getHomePhone() {
		return homePhone;
	}
	public void setHomePhone(String homePhone) {
		this.homePhone = homePhone;
	}
	
	public String getMobilePhonePro() {
		return mobilePhonePro;
	}
	public void setMobilePhonePro(String mobilePhonePro) {
		this.mobilePhonePro = mobilePhonePro;
	}
	
	public String getOfficePhone() {
		return officePhone;
	}
	public void setOfficePhone(String officePhone) {
		this.officePhone = officePhone;
	}
	
	public String getHomePage() {
		return homePage;
	}
	public void setHomePage(String homePage) {
		this.homePage = homePage;
	}
	
	public String getMailPro() {
		return mailPro;
	}
	public void setMailPro(String mailPro) {
		this.mailPro = mailPro;
	}
	
	public String getMailPerso() {
		return mailPerso;
	}
	public void setMailPerso(String mailPerso) {
		this.mailPerso = mailPerso;
	}
	
	public String getPicPath() {
		return picPath;
	}
	public void setPicPath(String picPath) {
		this.picPath = picPath;
	}
	
	public String getOther() {
		return other;
	}
	public void setOther(String other) {
		this.other = other;
	}
	
	/**
	 * save the contact in a formated file 
	 * @param filename the name of the file
	 * @return true on success
	 */
	public boolean save(String filename){
		String res = "";
		res+=name+"\n";
		res+=firstName+"\n";
		res+=companyAddress+"\n";
		res+=mobilePhone+"\n";
		res+=homePhone+"\n";
		res+=mobilePhonePro+"\n";
		res+=officePhone+"\n";
		res+=homePage+"\n";
		res+=mailPro+"\n";
		res+=mailPerso+"\n";
		res+=picPath;
		res+=other;
		File file = new File(filename);
        try {
            if (!file.exists()) {
                file.createNewFile();
            }
            FileWriter fw = new FileWriter(file.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(res);
            bw.close();
        } catch (Exception e) {
            System.out.println("error : " + e);
            JOptionPane.showMessageDialog(null, "Error : " + e);
            e.printStackTrace();
        }
		return true;
	}

}
